package ui

import (
	"log"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"

	"github.com/tidwall/pretty"
)

func JsonUi(w fyne.Window) (c *fyne.Container) {

	c1 := widget.NewEntry()
    
	c2 := widget.NewEntry()
	c3 := widget.NewButton("json格式化", func() {
		log.Println(c1.Text)
		res := pretty.Pretty([]byte(c1.Text))
		c2.SetText(string(res))
	})
	c4 := widget.NewButton("json压缩", func() {
		log.Println(c1.Text)
		res := pretty.Ugly([]byte(c1.Text))
		c2.SetText(string(res))
	})
	btn := container.New(layout.NewHBoxLayout(), c3, c4)

	content := layout.NewBorderLayout(nil, btn, nil, nil)
	c = container.New(content, btn, container.New(layout.NewGridLayoutWithColumns(2), c1, c2))
	return
}
